
function createMedAnnualContrastTable(xAxis, series, showPercent,valid,dataAnnualContrastDiv) {
	$("#"+dataAnnualContrastDiv).append('<table class="mintable" align="left"  id="'+dataAnnualContrastDiv+'Table" width="780px" border="1" ></table><br/>');
	if($.browser.msie){		
		$("#"+dataAnnualContrastDiv).append("</br>");
	}
	var thead = "<th></th>";
	for ( var x = 0; x < xAxis.length-1; x++) {
		thead += "<th>" + xAxis[x] + "</th>";
	}

	$("#"+dataAnnualContrastDiv+"Table").append("<tr>" + thead + "<th>Total</th></tr>");
	/*	 
	if (showPercent) {
		for ( var j = series.length - 1; j >= 0; j--) {
			if (j != series.length - 1) {
				var nextTr = "<th> VS " + series[j].name + "</th>";
				for ( var i = 0; i < xAxis.length; i++) {
					if( i < series[j].data.length){
						nextTr += "<td>" + leftTwoDecIgnoreZero(series[series.length - 1].data[i] / series[j].data[i] * 100) + "</td>";
					}else{
						nextTr+="<td></td>";
					}
				}
			}
		}
		//计算与上一年度同比增长的情况 total1 是计算当年有月份记录的总数，total2 是计算上一年度同等月份数下的记录总数
		var total1=0;var total2=0;
		for(var k=0;k<valid[valid.length-1].data.length;k++){			
			for(var n=0;n<valid[valid.length-1].data[k].data.length;n++){
				total1+=valid[valid.length-1].data[k].data[n];
			}			
		}
		for(var k=0;k<valid[0].data.length ;k++){
			for(var n=0;n<valid[0].data[k].data.length && n<valid[valid.length-1].data[0].data.length;n++){			
				total2+=valid[0].data[k].data[n];
			}			
		}
		
		$("#"+dataAnnualContrastDiv+"Table").append("<tr>" + nextTr + "<td>"+leftTwoDecIgnoreZero(1.0*total1/total2*100)+"</td></tr>");
	}
	*/
	for ( var j =  0; j <=series.length - 1; j++) {
		var nextTr = "<th> " + series[j].name + "</th>";
		var totalCount = 0;
		for ( var i = 0; i < xAxis.length-1; i++) {
			if( i < series[j].data.length){	
				if (null != series[j].data[i]) {
					nextTr += "<td>" + series[j].data[i] + "%</td>";
				}else{
					nextTr+="<td></td>";
				}
				totalCount += series[j].data[i];
			}else{
				nextTr+="<td></td>";
			}
		}
		
		var medTotal=0;
		var CNIsTotal=0;
		if('livingDataAnnualContrastDiv'==dataAnnualContrastDiv){		
			for(var n=0;n<valid[j].livingData.length;n++){
				medTotal+=valid[j].livingData[n];
			}			
		}else{			
			for(var k=0;k<valid[j].data.length;k++){
				for(var n=0;n<valid[j].data[k].data.length;n++){
					medTotal+=valid[j].data[k].data[n];
				}
			}
		}
		for(var l=0;l<valid[j].CNIsTotal.length ;l++){
			CNIsTotal+=valid[j].CNIsTotal[l];
		}
		nextTr += "<th>"+leftDecIgnoreZeroWithPercent(medTotal,CNIsTotal,2)+"</th>";
		
		$("#"+dataAnnualContrastDiv+"Table").append("<tr>" + nextTr + "</tr>");
	}
}
//初始化统计图的展示形式及数据,生成图和表
function createTableAndChart(action) {
	var showPercent = false;
	initLeftMemu();
	var data = getUrlData();
	var msg = getData(data, action);
	var seriesData = ""; //按series的格式{name:name,data:data}接收数据，最终转成json格式
	var livingSeriesData="";	
	var valid = msg.valid;
	var xTitle = "Time(M)";	
	if (valid[0].year != valid[valid.length - 1].year && valid.length <= 3) {
		showPercent = true;
	}
	for ( var i = 0; i < valid.length; i++) {
		for ( var n = 0; n < valid[i].data.length; n++) {
			var percentData="";
			var medTotal=0;
			var CNIsTotals=0;
			for(var k=0;k<valid[i].data[n].data.length;k++){
				medTotal+=valid[i].data[n].data[k];
				CNIsTotals+=valid[i].CNIsTotal[k];
				percentData += leftDec(valid[i].data[n].data[k],valid[i].CNIsTotal[k],2)+",";				
			}
			for(var k=valid[i].data[n].data.length;k<12;k++){
				percentData+="'null',";
			}			
			percentData+=leftDec(medTotal,CNIsTotals,2);
			seriesData += "{name:'" + valid[i].year + " " + (valid[i].data[n].type.length == 1 ? valid[i].data[n].type + valid[i].tx : valid[i].tx + " " + valid[i].data[n].type)
					+ "',data:[" + eval("["+percentData+"]") + "]},";

		}
		var percentData="";
		var medTotal=0;
		var CNIsTotals=0;
		for(var n=0;n<valid[i].livingData.length;n++){		
				medTotal+=valid[i].livingData[n];
				CNIsTotals+=valid[i].CNIsTotal[n];
				percentData += leftDec(valid[i].livingData[n],valid[i].CNIsTotal[n],2)+",";				
		}
		for(var k=valid[i].livingData.length;k<12;k++){
			percentData+="'null',";
		}			
		percentData+=leftDec(medTotal,CNIsTotals,2);		
		livingSeriesData +="{name:'"+valid[i].year+" "+valid[i].name+" L"+valid[i].tx+"',data:["+eval("["+percentData+"]")+"]},";
		
	}
	var xAxisCategories = "['Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sep','Oct','Nov','Dec','Total']";
	seriesData = seriesData.substr(0, seriesData.length - 1);	
	createTheme();
	var options = createOptionsSeriesType('container',data.type);
	options.xAxis.categories = eval("(" + xAxisCategories + ")");//将读取到的数据转成json数组格式
	options.series = eval("[" + seriesData + "]");//将图例数据部分转成json数组格式
	options.xAxis.title.text = xTitle;
	options.yAxis.title.text = "Percent";
	options.title.text =replaceWithChar(data.title, "_", " ").replace("TAC","TAC(G)"); //" Number Stat. By Month";

	createMedAnnualContrastTable(options.xAxis.categories, options.series, showPercent,valid,'dataAnnualContrastDiv');
	createInValidTable(msg.invalid,'invalidTableDiv');
	createChart(options);
	
	$("#chartContainer").append("<div><div id='livingChart' style='width: 780px;  margin: 0 auto;'></div><br/><div id='livingDataAnnualContrastDiv' class='dataDivAndChartDiv'></div><br/><div id='livingInvalidTableDiv' class='dataDivAndChartDiv' ></div><br/>");
	
	options.series=eval("["+livingSeriesData.substr(0,livingSeriesData.length-1)+"]");
	options.title.text=options.title.text.substr(0,5)+"L"+options.title.text.substr(5);
	options.chart.renderTo='livingChart';
	createMedAnnualContrastTable(options.xAxis.categories, options.series, showPercent,valid,'livingDataAnnualContrastDiv');
	createInValidTable(msg.livingInvalid,'livingInvalidTableDiv');
	createChart(options);
}
createTableAndChart('getChart2_2_0_5');